import React from 'react';

import './barCode.scss';

export default class extends React.Component {

    barSet = new Set();

    componentWillReceiveProps({value}){
        if(value && !this.barSet.has(value)){
            this.draw(value);
            this.barSet.add(value);
        }
    }

    draw(value){
        try {
            JsBarcode(this.refs.bar, value, {
                flat: true,
                width: 2,
                height: 70,
                format: "EAN13",
            });
        } catch (e){}
    }

    render(){
        var {className = ''} = this.props;
        return <svg className={`barcode ${className}`} ref="bar" />;
    }

}
